import { _decorator, Component, Label, Node, NodeEventType, ProgressBar } from 'cc';
import { UIBase } from './UIBase';
import { GameData } from './GameData';
import { levelData } from './levelData';
import { UIMgr } from './UIMgr';
import { Game } from './Game';
const { ccclass, property } = _decorator;

@ccclass('Select')
export class Select extends UIBase {
    private level1: Node = null;
    private level2: Node = null;
    private level3: Node = null;
    private arrow:Node=null;
    private levelData:number=0;
    oninit(...rest: any[]): void {
        this.addClickEventL("_CloseBtn1",()=>{
            this.closeUI("Select",true);
            this.openUI("Game","Normal",()=>{
                //如果第一次打开则不需要重启
                if(UIMgr.instance.getUI<Game>("Game").fristStart){
                    UIMgr.instance.getUI<Game>("Game").fristStart=false;
                    return;
                }
                UIMgr.instance.getUI<Game>("Game").isRestart=true;
                UIMgr.instance.getUI<Game>("Game").isover=false;
                UIMgr.instance.getUI<Game>("Game").reStart();
            });
        })
        this.arrow=this.getNode("_Arrow");
        this.level1=this.getNode("_level1");
        this.level2 = this.getNode("_level2");
        this.level3 = this.getNode("_level3");
        this.level1.on(NodeEventType.MOUSE_DOWN,()=>{this.arrowMove(this.level1)}, this);
        this.level2.on(NodeEventType.MOUSE_DOWN,()=>{this.arrowMove(this.level2)}, this);
        this.level3.on(NodeEventType.MOUSE_DOWN,()=>{this.arrowMove(this.level3)}, this);
        //接收数据
        this.levelData=this.level2.getComponent(levelData).Score;
        GameData.levelscore=this.levelData;
    }
    arrowMove(level:Node){
        this.arrow.setPosition(level.position.x,100);
        //接收数据
        this.levelData=level.getComponent(levelData).Score;
        GameData.levelscore=this.levelData;
    }
}


